﻿Public Class frmChinh
    Private Client As New GTClient()

    Private Sub frmChinh_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim dt = New DataTable()
        dt.Columns.Add("MaNgonNgu")
        dt.Columns.Add("TenNgonNgu")
        dt.Rows.Add("vi", "Tiếng Việt")
        dt.Rows.Add("en", "Tiếng Anh")
        dt.Rows.Add("zh-CN", "Tiếng Trung (Giản thể)")
        cbbTu.DataSource = dt
        cbbTu.SelectedIndex = 1

        dt = New DataTable()
        dt.Columns.Add("MaNgonNgu")
        dt.Columns.Add("TenNgonNgu")
        dt.Rows.Add("vi", "Tiếng Việt")
        dt.Rows.Add("en", "Tiếng Anh")
        dt.Rows.Add("zh-CN", "Tiếng Trung (Giản thể)")
        cbbSang.DataSource = dt
    End Sub

    Private Sub btnDao_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDao.Click
        Dim t = cbbSang.SelectedIndex
        cbbSang.SelectedIndex = cbbTu.SelectedIndex
        cbbTu.SelectedIndex = t
    End Sub

    Private Sub btnDich_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDich.Click
        Try
            txtSang.Text = Client.Download(
                "http://translate.google.com/translate_a/t",
                DownloadType.ContentUTF8,
                "client", "t",
                "text", txtTu.Text,
                "hl", "en",
                "sl", cbbTu.SelectedValue,
                "tl", cbbSang.SelectedValue,
                "ie", "UTF-8",
                "oe", "UTF-8",
                "multires", 1,
                "otf", 1,
                "ssel", 3,
                "ssel", 3,
                "sc", 1
            ).split("""")(1)
        Catch ex As Exception
            txtSang.Text = ""
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub btnTuTiengViet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTuTiengViet.Click
        cbbTu.SelectedIndex = 0
    End Sub

    Private Sub btnTuTiengAnh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTuTiengAnh.Click
        cbbTu.SelectedIndex = 1
    End Sub

    Private Sub btnTuTiengTrun_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTuTiengTrun.Click
        cbbTu.SelectedIndex = 2
    End Sub

    Private Sub btnSangTiengViet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSangTiengViet.Click
        cbbSang.SelectedIndex = 0
    End Sub

    Private Sub btnSangTiengAnh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSangTiengAnh.Click
        cbbSang.SelectedIndex = 1
    End Sub

    Private Sub btnSangTiengTrung_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSangTiengTrung.Click
        cbbSang.SelectedIndex = 2
    End Sub

    Private Sub txtTu_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtTu.KeyDown
        If e.Control And e.KeyCode = Keys.A Then
            txtTu.SelectAll()
            e.SuppressKeyPress = True
        ElseIf e.KeyCode = Keys.Enter Then
            btnDich_Click(Nothing, Nothing)
            e.SuppressKeyPress = True
        End If
    End Sub

    Private Sub txtSang_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtSang.KeyDown
        If e.Control And e.KeyCode = Keys.A Then
            txtSang.SelectAll()
            e.SuppressKeyPress = True
        End If
    End Sub

    Private Sub lblPowerBy_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lblPowerBy.LinkClicked
        Process.Start("https://translate.google.com.vn")
    End Sub

    Private Sub lblCodeBy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblCodeBy.Click
        Process.Start("https://www.facebook.com/luong.xuan.manh")
    End Sub
End Class
